//import photo from '@/assets/images/photo.png'
export function getCurrentTime(fields = 's',time=null) {
    const date =time? new Date(time):new Date();
    return toTimeStr(date,fields);
}
export function utcToTime(utc,fields = 's') {
    const date = new Date(utc);
    return toTimeStr(date,fields);

}
export function getForm(from,to){
    Object.keys(to).forEach(item=>{
        to[item]=from[item];
    })
}
function toTimeStr(date,fields){
    let str = '';
    let y = date.getFullYear().toString();
    let m = (date.getMonth() + 1).toString();
    m = m.length === 1 ? '0' + m : m
    let d = date.getDate().toString();
    d = d.length === 1 ? '0' + d : d
    let h = date.getHours().toString();
    h = h.length === 1 ? '0' + h : h
    let i = date.getMinutes().toString();
    i = i.length === 1 ? '0' + i : i
    let s = date.getSeconds().toString();
    s = s.length === 1 ? '0' + s : s
    if (fields === 'y') {
        str = y;
    }
    if (fields === 'm') {
        str = y + '-' + m
    }
    if (fields === 'd') {
        str = y + '-' + m + '-' + d
    }
    if (fields === 'h') {
        str = y + '-' + m + '-' + d + ' ' + h
    }
    if (fields === 'i') {
        str = y + '-' + m + '-' + d + ' ' + h + ':' + i
    }
    if (fields === 's') {
        str = y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s
    }
    return str;
}
export function getWeek(time=null){
    const date=time?new Date(time):new Date();
    const weekArr=['星期日','星期一','星期二','星期三','星期四','星期五','星期六']
    return weekArr[date.getDay()];
}
export function getMonth(timestamp=new Date().getTime()/1000){
    const date = new Date(timestamp * 1000);
    const currentMonth = date.getMonth() + 1;

    const result = [];

    for (let i = 0; i < 12; i++) {
        let month = (currentMonth + i) % 12;
        if (month === 0) month = 12;
        result.push(`${month}月`);
    }

    return result;
}
export function getRandomData(max,min,length){
    let arr=[];
    for (let i=0;i<length;i++){
        arr.push((Math.random()*(max-min)+min).toFixed(0))
    }
    return arr;
}

export function getMapDialogDom(type){
    let dom=null;
    dom=document.createElement('div');
    dom.className='map-dialog';
    let dialogTitle=document.createElement('div');
    dialogTitle.className='dialog-title';
    let dialogBody=document.createElement('div');
    dialogBody.className='dialog-body';
    if(type===1){
        const text=[
            '南向北摄像头',
            '北向南摄像头',
            '南向北摄像头',
            '南向北摄像头',
        ]
        dialogTitle.innerText='辖区地图';
        for (let i=0;i<data.length;i++){
            const row=data[i];
            let infoItem=document.createElement('div');
            let text=document.createElement('div');
            text.innerText=row.name;
            text.className='text'
            infoItem.appendChild(text)
            let value=document.createElement('div');
            value.innerText=row.value
            value.className='value'
            infoItem.appendChild(value)
            if(i>=3){
                infoItem.className='info-item full'
            }else {
                infoItem.className='info-item'
            }
            dialogBody.appendChild(infoItem)
        }
    }else {

    }
    dom.appendChild(dialogTitle)
    dom.appendChild(dialogBody)
    return dom;
}

export function inverted(array){
    let result=[];
    array.forEach(item=>{
        result.push([item[1],item[0]])
    })
    return JSON.parse(JSON.stringify(result))
}

export function FeatureCollectionLineString(data){
    return {
        type: 'FeatureCollection',
            features: [
        {
            type: 'Feature',
            properties: {},
            geometry: {
                type: 'LineString',
                coordinates: [
                    ...data
                ],
            },
        },
    ],
    }
}
